import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

// ignore: must_be_immutable
class LocalNavWebWidget extends StatefulWidget {
  String title;
  String url;

  LocalNavWebWidget(this.url, this.title);

  @override
  _LocalNavWebWidgetState createState() =>
      _LocalNavWebWidgetState(title: title, url: url);
}


class _LocalNavWebWidgetState extends State<LocalNavWebWidget> {
  String url;
  String title;

  _LocalNavWebWidgetState({this.url, this.title});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      ///隐藏Debug标志
      debugShowCheckedModeBanner: false,
      home: Scaffold(
          body: Container(
            child: WebviewScaffold(
              url: url,
              appBar: AppBar(
                centerTitle: true,
                backgroundColor: Colors.white,
                title:
                Text(this.title,
                    style: TextStyle(
                      fontStyle: FontStyle.normal,
                      color: Colors.black,
                    )),
                actions:[
                  IconButton(icon: Icon(
                    Icons.add_to_drive,
                    color: Colors.black,
                  ),
                      onPressed: (){
                        //防止回退到错误页面执行销毁当前页面
                        Navigator.of(context).popUntil((route) => false);
                        //执行跳转路由
                        Navigator.pushNamed(context, '/home');
                      }),
                ],
              ),
              //当WebView没加载出来前显示
              initialChild: Container(
                color: Colors.white,
                child: Center(
                  child: Text("神秘物体正在加载中...."),
                ),
              ),
            ),
          )),
    );
  }
}
